package com.atguigu.gmall.realtime.utils;

import scala.annotation.meta.param;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author jason
 * @create 2022-04-16 21:59
 */
public class ThreadPoolUtil {
    private static ThreadPoolExecutor threadPoolExecutor = null;

    //    私有化构造器
    private ThreadPoolUtil() {
    }

    public static ThreadPoolExecutor getThreadPool() {
        if (threadPoolExecutor == null) {
//            上锁
            synchronized (ThreadPoolUtil.class) {
//                如果为空在创建
                if (threadPoolExecutor == null) {
                    threadPoolExecutor = new ThreadPoolExecutor(8,
                            16,
                            1L, TimeUnit.MINUTES,
                            new LinkedBlockingDeque<>()
                    );
                }
            }

        }
        return threadPoolExecutor;
    }
}
//  * @param corePoolSize the number of threads to keep in the pool, even
//        *        if they are idle, unless {@code allowCoreThreadTimeOut} is set
//线程池核心数量  4
//        * @param maximumPoolSize the maximum number of threads to allow in the
//        *        pool
//线程池最大数量  10 队列满了才会来创建
//        * @param keepAliveTime when the number of threads is greater than
//        *        the core, this is the maximum time that excess idle threads
//        *        will wait for new tasks before terminating.
//线程池最大存活时间   30 一直没用就销毁
//        * @param unit the time unit for the {@code keepAliveTime} argument
////线程池最大存活时间  的单位 比如 s 一直没用就销毁
//        * @param workQueue the queue to use for holding tasks before they are
//        *        executed.  This queue will hold only the {@code Runnable}
//        *        tasks submitted by the {@code execute} method.
//任务来太多了 暂时没有线程处理就放这个队列里面  是等到这个队列满了才会去创建新的线程 默认值Long的最大